#include "stack.h"

//初始化栈
void StackInit(Stack* ps)
{
  assert(ps);

  ps->avl=NULL;
  ps->capacity=0;
  ps->top=0;
}
void StackDectcy(Stack* ps)
{
   assert(ps);
   free(ps->avl);
   ps->capacity=ps->top=0;
}
void StackPush(Stack* ps,Class x)
{
  assert(ps);
  if(ps->capacity==ps->top)
  {
    int size=ps->capacity==0?4:ps->capacity*2;
    Class* tmp=(Class*)realloc(ps->avl,sizeof(Stack)*size);
    if(!tmp)
    {
      exit(-1);
    }
    ps->avl=tmp;
    ps->capacity=size;
  }

    ps->avl[ps->top]=x;
    ps->top++;

}

void StackPop(Stack* ps)
{
  assert(ps);

  if(ps->top>0)
  {
    ps->top--;
  }
}
Class StackTop(Stack* ps)
{
  assert(ps);
  if(ps->top>0)
  return ps->avl[ps->top-1];
  
  exit(-1);
}
int StackSize(Stack* ps)
{
  assert(ps);
  return ps->top;
}
int StackEmpty(Stack *ps)
{
  assert(ps);
  return ps->top==0;
}

